package com.demo.controller;

import cn.hutool.json.JSON;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

/**
 *
 */
@RestController
@RequestMapping("/receivePushMessage")
public class ReceivePushMessageController {

    private final Logger logger = LoggerFactory.getLogger(ReceivePushMessageController.class);

    @GetMapping("/helloWorld")
    public String demo() throws Exception {
        logger.warn("hello world by logger");
        return "hello world";
    }

    @PostMapping("/seeAlarm")
    public String seeAlarm(@RequestBody String alarm) throws Exception {
        JSON workOrderJson = JSONUtil.parse(alarm);
        JSONObject jsonObject = workOrderJson.toBean(JSONObject.class);
        logger.warn(jsonObject.toString());
        return "400";
    }

    @PostMapping("/seeWorkOrder")
    public String seeWorkOrder(@RequestBody String workOrder) throws Exception {
        JSON workOrderJson = JSONUtil.parse(workOrder);
        JSONObject jsonObject = workOrderJson.toBean(JSONObject.class);
        logger.warn(jsonObject.toString());
        return "400";
    }

    @PostMapping("/seeDevice")
    public String seeDevice(@RequestBody String device) throws Exception {
        JSON workOrderJson = JSONUtil.parse(device);
        JSONObject jsonObject = workOrderJson.toBean(JSONObject.class);
        logger.warn(jsonObject.toString());
        return "400";
    }
}
